// pages/pkrecording/pkrecording.js
var app = getApp(); //获取应用实例
const quote = app.globalData.quote;
const mta = quote.mta;
const api = quote.api;

Page({

    /**
     * 页面的初始数据
     */
    data: {
        winHeight: "", //窗口高度
        currentTab: 0, //预设当前项的值
        openID: '',
        pageIndex: 0,
        Tyep: 0,
        showNone: false,
        loadingHidden: false,
        timerList: "", //按时间排序
        rankList: "", //按排名排序
        fractionList: "" //按分数排名
    },
    //nav导航切换
    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function(options) {
        var that = this
        console.log(app.globalData.openId)
        var openID = app.globalData.openId

        that.setData({
            openID: openID
        })

        that.timer()

        wx.getSystemInfo({
            success: function(res) {
                var clientHeight = res.windowHeight,
                    clientWidth = res.windowWidth,
                    rpxR = 750 / clientWidth;
                var calc = clientHeight * rpxR - 100;
                //console.log(calc)
                that.setData({
                    winHeight: calc
                });
            }
        });
    },
    //按时间获取
    timer: function() {
        var that = this;
        wx.showLoading({
            title: '加载中...',
        })
        var dataDic = {
            OpenId: app.globalData.openId,
            Type: 0, //排序方式
            pageIndex: that.data.pageIndex, //页码
            pageSize: 10 //页大小
        };
        api.methodGetDailySortByDifferentType({
            dataDic: dataDic,
            success: function(res) {
                wx.hideLoading();
                console.log(res)
                if (res.data.data.length > 0) {
                    that.setData({
                        timerList: res.data.data
                    })
                    console.log(that.data)
                }
                that.setData({
                    currentTab: 0,
                    pageIndex: 0,
                    showNone: false,
                })
            }
        })
    },
    //按排名
    rank: function() {
        var that = this;
        wx.showLoading({
            title: '加载中...',
        })
        var dataDic = {
            OpenId: app.globalData.openId,
            Type: 1, //排序方式
            pageIndex: that.data.pageIndex, //页码
            pageSize: 10 //页大小
        };
        api.methodGetDailySortByDifferentType({
            dataDic: dataDic,
            success: function(res) {
                wx.hideLoading();
                console.log(res)
                if (res.data.data.length > 0) {
                    that.setData({
                        rankList: res.data.data
                    })
                    console.log(that.data)
                }
                that.setData({
                    currentTab: 1,
                    pageIndex: 0,
                    showNone: false,
                })
            }
        })
    },
    //按分数
    fraction: function() {
        var that = this;
        wx.showLoading({
            title: '加载中...',
        })
        var dataDic = {
            OpenId: app.globalData.openId,
            Type: 2, //排序方式
            pageIndex: that.data.pageIndex, //页码
            pageSize: 10 //页大小
        };
        api.methodGetDailySortByDifferentType({
            dataDic: dataDic,
            success: function(res) {
                wx.hideLoading();
                console.log(res)
                if (res.data.data.length > 0) {
                    that.setData({
                        fractionList: res.data.data
                    })
                    console.log(that.data)
                }
                that.setData({
                    currentTab: 2,
                    pageIndex: 0,
                    showNone: false,
                })
            }
        })
    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function() {
        var that = this;
        wx.request({
            url: '',
            data: {},
            method: 'GET',
            complete: function(res) {
                wx.stopPullDownRefresh();
            }
        })
    },
    // lower:function(e){
    //   console.log("+++++")
    //  console.log(e)
    //  var current = e.currentTarget.dataset.current
    //  console.log(current)
    //  var that = this;

    //  if (that.data.showNone) {
    //    return
    //  }
    //  console.log('下拉触底刷新')
    //  that.setData({
    //    pageIndex: that.data.pageIndex + 1
    //  })
    // },

})